import { mapGetters } from 'vuex';

export default {
  data() {
    return {
      /* 获取一体杠列表的分页参数 */
      pageParams: {
        page: 1,
        pageSize: 15,
        poleName: undefined,
        poleNumber: undefined,
        poleStatus: null,
      },
      /* 是否处于加载列表状态 */
      loading: false,
    };
  },
  methods: {
    /* 获取一体杠列表的回调函数 */
    async fetchPoleList() {
      try {
        this.loading = true;
        await this.$store.dispatch('manageStore/fetchPoleList', this.pageParams);
      } catch (error) {
        this.$message.error(error.message);
      } finally {
        this.loading = false;
      }
    },
    /* 分页器size变化的回调函数 */
    handleSizeChange(pageSize) {
      this.pageParams.pageSize = pageSize;
      this.fetchPoleList();
    },
    /* 分页器page变化的回调函数 */
    handleCurrentChange(page) {
      this.pageParams.page = page;
      this.fetchPoleList();
    },

    formatterPoleStatus(row, column, cellValue, index) {
      const MAP = { 0: '正常', 1: '异常' };
      return MAP[row.poleStatus] || '未知';
    },
    formatterPoleType(row, column, cellValue, index) {
      const MAP = { 'entrance': '出口', 'export': '入口' };
      return MAP[row.poleType] || '未知';
    },
  },
  computed: {
    ...mapGetters('manageStore', ['poleList', 'total']),
  },
  mounted() {
    this.fetchPoleList();
  },
};
